/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import AdminOperations.AdminManageMembers;
import Utility.MemberAccountUtility;
import beans.AddAdminBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import xmlMapping.Member;

/**
 *
 * @author ABDELMOHSEN
 */
public class AddAdmin extends org.apache.struts.action.Action {
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.getSession().removeAttribute("mesg");
        AddAdminBean bean=(AddAdminBean)form;
        MemberAccountUtility util=new MemberAccountUtility();
        Member m=util.getAccountByName(bean.getAdminName());
        if(m==null){
            request.getSession().setAttribute("mesg", "Username Not found");
            return mapping.findForward("failed");
        }
        AdminManageMembers model=new AdminManageMembers();
        model.promotToAdmin(m.getMemberId(), (Integer)request.getSession().getAttribute("id"));
        return mapping.findForward("done");
    }
}
